package t1dao;

import java.util.List;

import t1bean.MajorBean;
import t1bean.StudentBean;


public class SetSql {
	/**
	 * @param student
	 * @param list
	 * @param sql
	 * @param m
	 * @return sql
	 * 
	 * 判断并修改sql语句，m==1时修改update语句，m==2时修改select和delete语句
	 */
	public String setSql(StudentBean student, List<Object> list, String sql, int m) {
		int n = 0;
		if (student.getNumber() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "number=?";
			list.add(student.getNumber());
			n = m;
		}
		if (student.getName() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "name=?";
			list.add(student.getName());
			n = m;
		}
		if (student.getMajorNumber() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "major_number=?";
			list.add(student.getMajorNumber());
			n = m;
		}
		return sql;
	}
	public String setSql(MajorBean major, List<Object> list, String sql, int m) {
		int n = 0;
		if (major.getNumber() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "number=?";
			list.add(major.getNumber());
			n = m;
		}
		if (major.getName() != null) {
			if (n == 1) {
				sql += ",";
			} else if (n == 2) {
				sql += " and ";
			}
			sql += "name=?";
			list.add(major.getName());
			n = m;
		}
		return sql;
	}
}
